﻿        
        var full_star_url = "/Content/images/rating-control/star-full.gif";
        var empty_star_url = "/Content/images/rating-control/star-empty.gif";
        
        set_initial_ratings ();
        
        function set_initial_ratings ()
        {
            // Make sure everything is loaded
            if (document.getElementById ("rating_locked_container") == null) {
                window.setTimeout ('set_initial_ratings ();', 200);
                return;
            }
            ratings_set (get_rating_average ());
        }
        
        function is_rating_locked ()
        {
            var cont = document.getElementById ("rating_locked_container");
            var list = cont.getElementsByTagName ("input");
            
            if (list [0] != null)
                return list [0].value == "true";
            return false;
        }
        
        function get_rating_average ()
        {
            var cont = document.getElementById ("rating_avg_container");
            var list = cont.getElementsByTagName ("input");
            
            if (list [0] != null)
                return list [0].value;
            return 0;
        }
        
        function ratings_clear ()
        {
            if (is_rating_locked ()) {
                set_cursor_for_stars (false);
                return;
            }

            set_cursor_for_stars (true);
                
            var i;
            var rating_average = get_rating_average ();
            var stars = document.getElementsByClassName("ratings-control-star");
           
            for (i = 0; i < rating_average; i++)
                stars [i].src = full_star_url;
            
            for ( ; i < 5; i++)
                stars [i].src = empty_star_url;
        }

        function ratings_set (rating)
        {
            if (is_rating_locked ()) {
                set_cursor_for_stars (false);
                return;
            }

            set_cursor_for_stars (true);

            var i;
            var stars = document.getElementsByClassName("ratings-control-star");
           
            for (i = 0; i < rating; i++)
                stars [i].src = full_star_url;
            
            for ( ; i < 5; i++)
                stars [i].src = empty_star_url;
                
            rating_average = rating;
        }

        function set_cursor_for_stars (enabled)
        {
            var stars = document.getElementsByClassName("ratings-control-star");
            if (enabled) {
                for (var i = 0; i < 5; i++) {
                    stars [i].style.cursor = "pointer";
                }
            } else {
                for (var i = 0; i < 5; i++)
                    stars [i].style.cursor = "default";
            }
        }
